function importFormatTime(timestamp, format) {
  let timestampSTR = parseInt(timestamp, 10)
  if (typeof timestampSTR === 'number' && timestampSTR < 10000000000) { // 假设时间戳是以秒为单位的
    timestampSTR *= 1000; // 转换为毫秒
  }
  const date = new Date(timestampSTR); 
  if (isNaN(date.getTime())) {
    throw new Error("无效的时间戳 ~");
  }
  const year = date.getFullYear();
  const month = ('0' + (date.getMonth() + 1)).slice(-2);
  const day = ('0' + date.getDate()).slice(-2);
  const hour = ('0' + date.getHours()).slice(-2);
  const minute = ('0' + date.getMinutes()).slice(-2);
  const second = ('0' + date.getSeconds()).slice(-2);
  return format.replace('Y', year)
 .replace('M', month)
 .replace('D', day)
 .replace('h', hour)
 .replace('m', minute)
 .replace('s', second);
}

module.exports = {
  importFormatTime: importFormatTime
}
